﻿using Biz.Core.Models;
using Biz.Core.Providers;
using MiniFox;
using MiniFox.Components;
using MiniFox.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Biz.Core.Services
{
    [AutoResolve]
    public class OrderService : IOrderService
    {
        [AutoWired]
        public IOrderDataProvider DataProvider
        {
            get; set;
        }

        public ResultObject<IEnumerable<OrderVo>> QueryOrderList(PagedQueryObject<OrderSearchModel> queryObject)
        {
            return this.DataProvider.QueryOrderList(queryObject);
        }

        public ResultObject<ViewTable> QueryOrders(PagedQueryObject<OrderSearchModel> queryObject)
        {
            throw new NotImplementedException("暂不实现，样例不搞那复杂");
        }

        public OrderVo CreateOrder(OrderDto orderDto)
        {
            orderDto.OrderId = SequenceGUID.NewGUID();// 非自增主键，需要创建带时间戳前缀的uuid
            if (this.DataProvider.CreateOrder(orderDto))
            {
                // 创建成功后读取新数据
                return this.DataProvider.GetOrder(orderDto.OrderId);
            }
            return null;
        }

        public OrderVo UpdateOrder(OrderDto orderDto)
        {
            if (this.DataProvider.UpdateOrder(orderDto))
            {
                // 更新成功后读取新数据
                return this.DataProvider.GetOrder(orderDto.OrderId);
            }
            return null;
        }

        public string DeleteOrder(string orderId)
        {
            if (this.DataProvider.DeleteOrder(orderId))
            {
                // 删除成功后返回原id
                return orderId;
            }
            return null;
        }

        public OrderVo OrderPay(string orderId)
        {
            if (this.DataProvider.OrderPay(orderId))
            {
                // 切换成功后读取新数据
                return this.DataProvider.GetOrder(orderId);
            }
            return null;
        }

        public OrderVo GetOrder(string orderId)
        {
            return this.DataProvider.GetOrder(orderId);
        }
    }
}
